package com.t.bricks.bussiness.controller.shoppingcart;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.t.bricks.bussiness.db.entity.shoppingcart.ShoppingCart;
import com.t.bricks.bussiness.model.shoppingcart.ConditionShoppingCart;
import com.t.bricks.bussiness.service.shoppingcart.ShoppingCartService;
import com.t.bricks.model.MsgEmity;
import com.t.bricks.utils.modules.web.FindByPageParam;

/**
 * 购物车控制层
 * @author HuangXinBian
 * @DateTime 2022年06月22日 15:25:32
 */
@RestController
@Api(value="购物车", tags={"购物车操作接口"})
@RequestMapping("/shopping/cart/")
public class ShoppingCartController {
	
	@Autowired
	private ShoppingCartService shoppingCartService;

	/**
	 * 删除数据
	 * @param iVersion
	 * @param id 记录编号
	 * @return MsgEmity
	 */
	@ApiOperation(value="删除数据")
	@RequestMapping(method={RequestMethod.POST}, value="/del")
	public MsgEmity del(Integer iVersion, String id) {
		return shoppingCartService.del(iVersion, id);
	}

	/**
	 * 新增数据
	 * @param shoppingCart 购物车实体对象
	 * @return MsgEmity
	 */
	@ApiOperation(value="新增数据", response=ShoppingCart.class)
	@RequestMapping(method={RequestMethod.POST}, value="/add")
	public MsgEmity add(@RequestBody ShoppingCart shoppingCart) {
		return shoppingCartService.add(shoppingCart);
	}

	/**
	 * 根据记录编号查询符合分页数据的某条记录
	 * @param id 记录编号
	 * @return MsgEmity
	 */
	@ApiOperation(value="根据记录编号查询符合分页数据的某条记录", response=ShoppingCart.class)
	@RequestMapping(method={RequestMethod.POST}, value="/find/page/row")
	public MsgEmity findByPageRow(String id) {
		return shoppingCartService.findByPageRow(id);
	}

	/**
	 * 查询分页数据
	 * @param findByPageParam 分页查询条件组合类
	 * 结构参考: {"page": 分页请求信息对象, "orders": 排序信息对象集合, "sLikeStr": 全文检索, "condition": 查询条件对象}
	 * @return MsgEmity 返回查询结果
	 */
	@ApiOperation(value="查询分页数据", response=ShoppingCart.class)
	@RequestMapping(method={RequestMethod.POST}, value="/find/page")
	public MsgEmity findByPage(@RequestBody FindByPageParam<ConditionShoppingCart> findByPageParam) {
		return shoppingCartService.findByPage(
				findByPageParam.getPage(),
				findByPageParam.getOrders(),
				findByPageParam.getsLikeStr(),
				findByPageParam.getCondition());
	}

	/**
	 * 修改数量
	 * @param uId 购物车记录
	 * @param iVersion 当前版本号
	 * @param iAppendCount 增加(减少)的数量
	 * @return MsgEmity
	 */
	@ApiOperation(value="修改数量", response=ShoppingCart.class)
	@RequestMapping(method={RequestMethod.POST}, value="/edit/count")
	public MsgEmity editCount(String uId, Integer iVersion, Integer iAppendCount) {
		return shoppingCartService.editCount(uId, iVersion, iAppendCount);
	}

	/**
	 * 批量删除数据
	 * @param ids 记录编号串(逗号分隔)
	 * @return MsgEmity
	 */
	@ApiOperation(value="批量删除数据")
	@RequestMapping(method={RequestMethod.POST}, value="/dels")
	public MsgEmity dels(String ids) {
		return shoppingCartService.dels(ids);
	}

}
